package com.fenye.controller;

import com.alibaba.fastjson.JSONObject;
import com.fenye.domain.Page;
import com.fenye.domain.Student;
import com.fenye.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 表现层
 */
@RestController
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;

    @RequestMapping("/find")
    public Object select(int pageno,int pagesize){
        int count=(pageno-1)*pagesize;
        List<Student> students=studentMapper.findall(count,pagesize);
        int totalcount=studentMapper.findpage();
        int totalpage=0;
        if(totalcount%pagesize==0){
            totalpage=totalcount/pagesize;
        }
        else {
            totalpage=totalcount/pagesize+1;
        }
        Page p=new Page(pageno,pagesize,totalpage,totalcount,students);
        return JSONObject.toJSONString(p);
    }

}
